<?php
class AppHelper {
	
	public static function getClientIp() {
		if(isset($_SERVER['HTTP_CLIENT_IP'])) {
			$ip = $_SERVER['HTTP_CLIENT_IP'];
		}
		elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
			$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
		}
		else{
			$ip = $_SERVER['REMOTE_ADDR'];
		}
		return $ip;
	}
	
	/**
	 * 获得章节最后翻译日期
	 * @param unknown_type $bookId
	 * @param unknown_type $chapterId
	 */
	public static function getChapterReleaseDate($bookId, $chapterId) {
		$timestamp = Yii::app()->db->createCommand()->from('{{module_'. $bookId .'_sections}} s')
						->select('t.addTime')
						->where('chapterId=?', array($chapterId))
						->order('t.addTime desc')
						->join('{{module_'. $bookId .'_translates}} t', 's.translateId=t.translateId')
						->queryScalar();
		if (!$timestamp ) return '----/--/--';
		return date('Y/m/d', $timestamp);
	}
}